//
//  ReadLimitedView.swift
//  WalkNovel
//
//  Created by Kevin on 2023/10/19.
//

import UIKit

class ReadLimitedView: UIView {
    
    lazy var bgImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "read_recharge_limited_bg"))
        image.wn_cornerWithBorder(10)
        return image
     }()

    lazy var topupLabel: UILabel = {
        let label = UILabel()
        label.text = "限時儲值"
        label.textColor = .init(named: "black_222222")
        label.font = .wn_font(name: .bold, size: 22)
        return label
    }()
        
    lazy var priceLabel: UILabel = {
        let label = UILabel()
        label.textColor = .init(named: "black_333333")
        label.font = .wn_font(name: .bold, size: 18)
        label.textAlignment = .center
        label.numberOfLines = 2
        return label
    }()
        
    lazy var sunBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setBackgroundImage(UIImage(named: "setting_topup_sun"), for: .normal)
        btn.setTitleColor(.init(named: "red_FE6390"), for: .normal)
        btn.titleLabel?.font = .wn_font(name: .bold, size: 12)
        btn.titleLabel?.textAlignment = .center
        return btn
    }()

    lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.backgroundColor = .init(named: "purple_AB95FE")
        label.textColor = .white
        label.font = .wn_font(name: .bold, size: 12)
        label.textAlignment = .center
        label.wn_cornerWithBorder(4)
        return label
    }()
                    
    var model: RechargeDetailModel? {
        didSet {
            if let m = model {
                sunBtn.setTitle("+\(m.disGold)%", for: .normal)
                let str = "花費 $ \(m.price)\n得到 \(m.gold) + \(m.goldGive) 金幣"
                priceLabel.attributedText = str.wn_numberChange(.init(named: "red_FE6390")!, .wn_font(name: .bold, size: 20))
                layoutIfNeeded()
            }
        }
    }
        
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(bgImage)
        bgImage.addSubview(topupLabel)
        bgImage.addSubview(priceLabel)
        bgImage.addSubview(sunBtn)
        bgImage.addSubview(timeLabel)
        bgImage.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        topupLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(20)
        }
        priceLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(topupLabel.snp.bottom).offset(12)
        }
        sunBtn.snp.makeConstraints { make in
            make.top.equalTo(topupLabel.snp.bottom).offset(4)
            make.right.equalTo(-6)
            make.size.equalTo(CGSize.init(width: 52, height: 52))
        }
        timeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(6)
            make.left.equalTo(6)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
